package com.blog.check.check;

import com.blog.check.resultenum.BlogTypeChkRsEnum;
import com.blog.check.resultenum.UserChkRsEnum;
import com.blog.dao.domain.BlogTypeDO;
import com.blog.dao.domain.UserDO;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

/**
 * 博客的类型检查
 *
 * @author 泡面ing
 * @date 2021/11/23
 */
@Service
public class BlogTypeCheck extends BaseCheck{


    public CheckResult checkJurId(){
        if (getUsername() == null){
            return CheckResult.failure(UserChkRsEnum.USER_IS_NOT_LOGIN);
        }
        UserDO userDO = userDAO.get(getUsername());
        if (!userDO.getJurId().equals("1")){
            return CheckResult.failure(UserChkRsEnum.INSUFFICIENT_USER_PERMISSIONS);
        }
        return CheckResult.success();
    }


    /**
     * 检查更新
     *
     * @param id id
     * @return {@link CheckResult}
     */
    public CheckResult checkUpdate(String id){
        // Non-logical check for update
        return checkUpdateNonLogical(id);
    }

    /**
     * 检查更新非逻辑
     *
     * @param id id
     * @return {@link CheckResult}
     */
    private CheckResult checkUpdateNonLogical(String id) {
        BlogTypeDO blogTypeDO = blogTypeDAO.get(id);
        if (ObjectUtils.isEmpty(blogTypeDO)){
            return CheckResult.failure(BlogTypeChkRsEnum.ILLEGAL_ID_NOT_EXIST,id);
        }
        return CheckResult.success();
    }
}
